package com.designmodel.observermodel;

/**
 * Created by
 *
 * @author touni
 * @date 2019/4/1
 * @time 17:09
 */
public class MainDemo {


    public static void main(String[] args) {
        //创建一个消息的发布者
        AbstractSubject definiteSubject = new DefiniteSubject();
        //创建消息的订阅者  订阅者可以有多个
        DefiniteObserver o1 = new DefiniteObserver("111");
        DefiniteObserver o2 = new DefiniteObserver("222");
        DefiniteObserver o3 = new DefiniteObserver("333");
        //注册观察者
        definiteSubject.registerObserver(o1);
        definiteSubject.registerObserver(o2);
        definiteSubject.registerObserver(o3);
        //发布消息
        definiteSubject.pushMessage("啦啦啦啦德玛西亚");
        System.out.println("================华丽的分割线====================");
        //取消订阅
        definiteSubject.removeObserver(o1);
        definiteSubject.pushMessage("今天是充满希望的一天");






    }
}
